
import { resolve } from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue2';
import vueJsx from '@vitejs/plugin-vue2-jsx';
import commonjs from 'vite-plugin-commonjs';
import basicSsl from '@vitejs/plugin-basic-ssl';

export default defineConfig({
  base: './',
  plugins: [vue(), vueJsx(), commonjs(), basicSsl()],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),
    },
    // 不建议忽略自定义导入类型的扩展名（例如.vue）
    extensions: ['.js', '.jsx', '.json', '.mjs'],
  },
  server: {
    port: 9033,
    host: true,
    open: true,
    https: true,
  },
  build: {
    target: 'ES2020', 
    lib: {
      entry: 'src/utils/logger.js',
      name: 'DrpHybridSDK',
      fileName: 'DrpHybridSDK'
    },
    rollupOptions: {
      external: /^lit/,
      output: {
        entryFileNames: '[name].js',
        chunkFileNames: '[name]-[hash].js',
        assetFileNames: '[name]-[hash][extname]',
      },
    }
    //会将相同类型的文件放在同一个文件夹里
    // rollupOptions: {
    //   output: {
    //     // Static resource classification and packaging
    //     chunkFileNames: 'assets/js/[name]-[hash].js',
    //     entryFileNames: 'assets/js/[name]-[hash].js',
    //     assetFileNames: 'assets/[ext]/[name]-[hash][extname]',
    //   },
    // },
  },
  // plugins: [
  //   legacy({
  //     targets: ['chrome < 60'],
  //   }),
  // ],
});
